import os
import sys
import shutil
from ccpm.pmbase import PluginBase
from ccpm.glan import Lan
from ccpm.constants import Constant

def fmt_verstr(verstr):
    nums = verstr[1:].split(".")
    return int(nums[0]) * 100 + int(nums[1]) * 10 + int(nums[2])


class CleanPlugin(PluginBase):

    PLUGIN_INFO = dict(
        name="clean",
        help="clean packages!"
    )

    def __init__(self):
        if not hasattr(self, "_inc"):
            self._inc = super().__init__(self.PLUGIN_INFO)
        return self._inc

    def parser_config(self, argparser):
        super().parser_config(argparser)

    def run(self, argpars):
        super().run(argpars)
        inspath = os.path.join(os.getcwd(), Constant.L_PACKINSTALL_DIR)
        if os.path.isdir(inspath):
            shutil.rmtree(inspath)
        self.logger.info(Lan.p(self.name, "RUN_CLEANSUC"))


__all__ = [
    "CleanPlugin"
]
